home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / lib / yotpin / src / colchg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-29  |  5.9 KB  |  274 lines

  1. /*
  2. *    Yamana's Otomeza Plug-in Tool
  3. *        色変更ポリゴン
  4. *    
  5. *    1995.08.13    
  6. *    1995.08.18    タイルパターンへの変更を可能にした
  7. *    1995.08.24    色の置換を可能にした
  8. *    
  9. */
  10. #include    "otome_pi.h"
  11.  
  12. const char longname[] = "DRAW  : カラーチェンジ";
  13. int            cnfg_max = 1;
  14. PI_CNFG        cnfg[] =
  15.             {    /* 1234567890123456 ,min,max,def,set */
  16.                 { "相互置換 →する"    ,  0,  1,  0,  0 },
  17.             };
  18.  
  19. #define    USE_TYPE    PI_DRAW_POLY
  20. #define    USE_ENV        PI_SET_ENV
  21. #include    "otome_pi.c"
  22.  
  23. /*******************************************************/
  24. /* ポリゴンの最大矩形座標を求める */
  25. void get_rectangle( fr )
  26. FRAME    *fr;
  27. {
  28.     unsigned int     minx,miny,maxx,maxy;
  29.     int     i,x,y;
  30.     
  31.     minx = miny = (-1);
  32.     maxx = maxy = 0;
  33.     for( i=0; i< WORD( g_para ) ; i++ )
  34.     {    x = WORD( g_para+2+i*4 );
  35.         y = WORD( g_para+4+i*4 );
  36.         if( x<minx )    minx = x;
  37.         if( x>maxx )    maxx = x;
  38.         if( y<miny )    miny = y;
  39.         if( y>maxy )    maxy = y;
  40.     }
  41.     fr->lupx = minx;    fr->lupy = miny;
  42.     fr->rdwx = maxx;    fr->rdwy = maxy;
  43.     
  44. }
  45.  
  46. /*****************************/
  47.  
  48. char Bit[]        = { 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01 };
  49.  
  50. /* 描画可能のとき !0 を返す */
  51.  
  52. #define        getMaskBit( _x, _y )    \
  53.         (pi_imge->edit[((_x)>>3) + (_y)*(pi_imge->size.x>>3) ]    \
  54.                     & Bit[ (_x) & 7] )
  55. #define        setMaskBit( _x, _y )    \
  56.         (pi_imge->edit[((_x)>>3) + (_y)*(pi_imge->size.x>>3) ]    \
  57.                     &= (Bit[ (_x) & 7] ^ 0xff) )
  58.  
  59.  
  60. void    setmask16( fr, col )
  61. FRAME    *fr;
  62. int     col;
  63. {
  64.     int     x,y,ypos,pos;
  65.     
  66.     for( y=fr->lupy; y<=fr->rdwy; y++ )
  67.     {    ypos = y*(pi_imge->size.x>>3);
  68.         
  69.         for( x=fr->lupx; x<=fr->rdwx; x++ )
  70.         {    
  71.             pos = (x>>3) + ypos;
  72.             if( pi_imge->edit[ pos ] == 0 )    /* 範囲外であるなら飛ばす */
  73.             {    x += (7-(x & 7));
  74.                 continue;
  75.             }
  76.             if( (pi_imge->edit[ pos ] & Bit[x & 7])==0 )
  77.                 continue;
  78.             
  79.             if( ((pi_imge->image[(x>>1) + y*(pi_imge->size.x>>1)]
  80.                     >>((x&1)? 4:0 )) & 0x0f)  != col )
  81.                 pi_imge->edit[ pos ] &= (Bit[x & 7]^0xff);
  82.             
  83.         }
  84.     }
  85. }
  86.  
  87. void    setmask256( fr, col )
  88. FRAME    *fr;
  89. int     col;
  90. {
  91.     int     x,y,ypos,pos;
  92.     
  93.     for( y=fr->lupy; y<=fr->rdwy; y++ )
  94.     {    ypos = y*(pi_imge->size.x>>3);
  95.         
  96.         for( x=fr->lupx; x<=fr->rdwx; x++ )
  97.         {    
  98.             pos = (x>>3) + ypos;
  99.             if( pi_imge->edit[ pos ] == 0 )    /* 範囲外であるなら飛ばす */
  100.             {    x += (7-(x & 7));
  101.                 continue;
  102.             }
  103.             if( (pi_imge->edit[ pos ] & Bit[x & 7])==0 )
  104.                 continue;
  105.             
  106.             if( pi_imge->image[ x + y * pi_imge->size.x ] != col )
  107.                 pi_imge->edit[ pos ] &= (Bit[x & 7]^0xff);
  108.             
  109.         }
  110.     }
  111. }
  112.  
  113. void    setmask32K( fr,col )
  114. FRAME    *fr;
  115. int     col;
  116. {
  117.     int     x,y,ypos,pos;
  118.     
  119.     for( y=fr->lupy; y<=fr->rdwy; y++ )
  120.     {    ypos = y*(pi_imge->size.x>>3);
  121.         
  122.         for( x=fr->lupx; x<=fr->rdwx; x++ )
  123.         {    
  124.             pos = (x>>3) + ypos;
  125.             if( pi_imge->edit[ pos ] == 0 )    /* 範囲外であるなら飛ばす */
  126.             {    x += (7-(x & 7));
  127.                 continue;
  128.             }
  129.             if( (pi_imge->edit[ pos ] & Bit[x & 7])==0 )
  130.                 continue;
  131.             
  132.             if( WORD( pi_imge->image +((x+y*pi_imge->size.x)<<1)) != col )
  133.                 pi_imge->edit[ pos ] &= (Bit[x & 7]^0xff);
  134.             
  135.         }
  136.     }
  137.     
  138. }
  139.  
  140. /**********************************************************************/
  141. void    colchg_16( fr,c0,c1 )
  142. FRAME    *fr;
  143. int     c0,c1;
  144. {
  145.     int     x,y,ypos,pos;
  146.     char    *p;
  147.     
  148.     for( y=fr->lupy; y<=fr->rdwy; y++ )
  149.     {    ypos = y*(pi_imge->size.x>>3);
  150.         
  151.         for( x=fr->lupx; x<=fr->rdwx; x++ )
  152.         {    
  153.             pos = (x>>3) + ypos;
  154.             if( pi_imge->edit[ pos ] == 0 )    /* 範囲外であるなら飛ばす */
  155.             {    x += (7-(x & 7));
  156.                 continue;
  157.             }
  158.             if( (pi_imge->edit[ pos ] & Bit[x & 7])==0 )
  159.                 continue;
  160.             
  161.             p = &pi_imge->image[(x>>1) + y*(pi_imge->size.x>>1)];
  162.             if( x & 1 )
  163.             {         if(((*p>>4)&0x0f)== c0 )    *p = (*p & 0x0f) | (c1<<4);
  164.                 else if(((*p>>4)&0x0f)== c1 )    *p = (*p & 0x0f) | (c0<<4);
  165.             }else
  166.             {         if( (*p & 0x0f)== c0 )        *p = (*p & 0xf0) | c1 ;
  167.                 else if( (*p & 0x0f)== c1 )        *p = (*p & 0xf0) | c0 ;
  168.             }
  169.         }
  170.     }
  171. }
  172.  
  173. void    colchg_256( fr,c0,c1 )
  174. FRAME    *fr;
  175. int     c0,c1;
  176. {
  177.     int     x,y,ypos,pos;
  178.     char    *p;
  179.     
  180.     for( y=fr->lupy; y<=fr->rdwy; y++ )
  181.     {    ypos = y*(pi_imge->size.x>>3);
  182.         
  183.         for( x=fr->lupx; x<=fr->rdwx; x++ )
  184.         {    
  185.             pos = (x>>3) + ypos;
  186.             if( pi_imge->edit[ pos ] == 0 )    /* 範囲外であるなら飛ばす */
  187.             {    x += (7-(x & 7));
  188.                 continue;
  189.             }
  190.             if( (pi_imge->edit[ pos ] & Bit[x & 7])==0 )
  191.                 continue;
  192.             
  193.             p = &pi_imge->image[ x + y*pi_imge->size.x ];
  194.             
  195.                  if( *p == c0 )    *p = c1;
  196.             else if( *p == c1 )    *p = c0;
  197.         }
  198.     }
  199. }
  200.  
  201. void    colchg_32K( fr,c0,c1 )
  202. FRAME    *fr;
  203. int     c0,c1;
  204. {
  205.     int     x,y,ypos,pos;
  206.     char    *p;
  207.     
  208.     for( y=fr->lupy; y<=fr->rdwy; y++ )
  209.     {    ypos = y*(pi_imge->size.x>>3);
  210.         
  211.         for( x=fr->lupx; x<=fr->rdwx; x++ )
  212.         {    
  213.             pos = (x>>3) + ypos;
  214.             if( pi_imge->edit[ pos ] == 0 )    /* 範囲外であるなら飛ばす */
  215.             {    x += (7-(x & 7));
  216.                 continue;
  217.             }
  218.             if( (pi_imge->edit[ pos ] & Bit[x & 7])==0 )
  219.                 continue;
  220.             
  221.             p = &pi_imge->image[ (x+y*pi_imge->size.x)<<1 ];
  222.             
  223.                  if( WORD(p) == c0 )    WORD(p) = (short)c1;
  224.             else if( WORD(p) == c1 )    WORD(p) = (short)c0;
  225.         }
  226.     }
  227.     
  228. }
  229.  
  230. /**********************************************************************/
  231.  
  232. int APL_exec()
  233. {
  234.     FRAME    fr;
  235.     int     mode;
  236.     
  237.     mode = cnfg[0].val;
  238.     
  239.     /* 矩形範囲を得る */
  240.     get_rectangle( &fr );
  241.     
  242.     if( mode )
  243.     {    if( PI_TILEFLG )    return ERROR;
  244.         
  245.         if( pi_imge->pix <8 )    colchg_16 ( &fr, PI_BACKCOL,PI_FORECOL );
  246.         if( pi_imge->pix==8 )    colchg_256( &fr, PI_BACKCOL,PI_FORECOL );
  247.         if( pi_imge->pix >8 )    colchg_32K( &fr, PI_BACKCOL,PI_FORECOL );
  248.         
  249.         return NOERR;
  250.     }
  251.     /* マスク設定 */
  252.          if( pi_imge->pix  < 8 )    setmask16 ( &fr, PI_BACKCOL );
  253.     else if( pi_imge->pix == 8 )    setmask256( &fr, PI_BACKCOL );
  254.     else if( pi_imge->pix  > 8 )    setmask32K( &fr, PI_BACKCOL );
  255.     
  256.     
  257.     EGB_writePage( EgbPtr, PI_PAGE );
  258.     EGB_mask     ( EgbPtr, EGB_MASK_ON );
  259.     
  260.     if( PI_TILEFLG )
  261.     {    EGB_tilePattern( EgbPtr, EGB_PAINTCOL,
  262.                     PI_TILE_X, PI_TILE_Y, PI_TILE_PAT );
  263.         EGB_paintMode( EgbPtr, EGB_PAINT_TILEF );
  264.     }else
  265.     {    EGB_color( EgbPtr, EGB_PAINTCOL,  PI_FORECOL );
  266.         EGB_paintMode( EgbPtr, EGB_PAINT_BETAFF );
  267.     }
  268.     
  269.     EGB_rectangle( EgbPtr, &fr );
  270.     
  271.     return NOERR;
  272. }
  273.  
  274.